// node的文件系统
const fs = require('fs')
const dirPath = 'images'
const sharp = require('sharp')
// 项目亮点
function convertToWebp(inputPath, outputPath, quality) {
    sharp(inputPath)
        .webp({quality:quality})
        .toFile(outputPath,(err,info)=>{
            console.log(outputPath,'done',new Date());
        })
}

fs.readdir('images', (err, files) => {
    // 拿到目录信息
    file.foreach(async (file) => {
        const filePath = `${dirPath}/${file}`
        const outputFilePath =
            `${dirPath}/${file.replace(/.jpe?g|.png/gi, '.webp')}`
        await convertToWebp(filePath, outputFilePath)
    })
})